package com.icangya.service.impl;

import com.icangya.DAO.*;
import com.icangya.domain.*;
import com.icangya.domain.RwGoodOrder;
import com.icangya.domain.User;
import com.icangya.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
/**
 * author:黄明浜
 * date:2017.10.13 PM: 5:00
 */
@Service("UserServiceImpl")
public class UserServiceImpl implements IUserService {

    @Autowired
    private IUserFootDAO userDAO;
    @Autowired
    private IUserBalanceDAO userBalanceDAO;
    @Autowired
    private IExpendRecordDAO expendRecordDAO;
    @Autowired
    private IRechargeRecordDAO rechargeDAO;
    @Autowired
    private IUserPointsRecordDAO pointsRecordDAO;
    @Autowired
    private IGoodsUpgradeRecordDAO goodsUpgradeRecordDAO;
    @Autowired
    private IGoodsSalesReturnRecordDAO goodsSalesReturnRecordDAO;
    @Autowired
    private IRwGoodOrderDAO rwGoodOrderDAO;
    @Autowired
    private IRedPacketRecordDAO redPacketRecordDAO;
    @Autowired
    private IRwUserBankDAO rwUserBankDAO;
    @Autowired
    private IUserOdevityRecordDAO userOdevityRecordDAO;
    @Autowired
    private IProxyLevelDAO proxyLevelDAO;

    @Autowired
    private IOdevityDAO  iOdevityDAO;

    @Autowired
    private IRedPacketRecordDAO  iRedPacketRecordDAO;

    @Autowired
    private IUserWithdrawRecordDAO  iUserWithdrawRecordDAO;

    @Override
    public List<Object> findAll(Integer pageNum) {
        return this.userDAO.findALlUser(pageNum);
    }

    @Override
    public Balance findBalanceByUserId(Long id) {
        return this.userBalanceDAO.findByUserId(id);
    }

    @Override
    public List<Object> findByUserExpendRecord(Long id ,Integer pageNum) {
        return this.expendRecordDAO.findByUserExpendRecord(id ,pageNum);
    }

    @Override
    public List<Object> findByUserRechargeRecord(Long id, Integer pageNum) {
        return this.rechargeDAO.findByUserRechargeRecord(id,pageNum);
    }

    @Override
    public List<Object> findByUserPointsRecord(Long id, Integer pageNum) {
        return this.pointsRecordDAO.getPointsRecordByUserId(id,pageNum);
    }

    @Override
    public List getRedPacketRecord(long uid) {
        return iRedPacketRecordDAO.getRedPacketRecord(uid);
    }

    @Override
    public User getUserByUid(Long id) {
        //return this.userDAO.selectUserByUid(id);
        return this.userDAO.get(id);
    }

    @Override
    public List getGoodsUpgradeByUserId(long id) {
        return this.goodsUpgradeRecordDAO.getGoodsUpgradeByUserId(id);
    }

    @Override
    public List<Object> goodSalesReturnRecord(Long uid, Integer pageNum) {
        return this.goodsSalesReturnRecordDAO.goodSalesReturnRecord(uid , pageNum);
    }

    @Override
    public List<Object> findOrderByUserId(Long uid, Integer pageNum) {
        return this.rwGoodOrderDAO.findOrderByUserId(uid,pageNum);
    }

    @Override
    public List<Object> findRedPacketRecordByUserId(Long uid, Integer pageNum) {
        return this.redPacketRecordDAO.findRedPacketRecordByUserId(uid,pageNum);
    }

    @Override
    public List<RwUserBank> findBankCarByUserId(long id) {
        return this.rwUserBankDAO.findBankCarByUserId(id);
    }

    @Override
    public List<Object> findOdevityByUserId(Long id, Integer pageNum) {
        return this.userOdevityRecordDAO.findOdevityByUserId( id , pageNum );
    }

    @Override
    public Long[] findUserLevelByUserId(Long id) {

        /*List<Object> level = new ArrayList<Object>();
        level.add(this.proxyLevelDAO.getFirstCount(id);//获取一级代理)
        level.add(this.proxyLevelDAO.getSecondCount(id));//获取二级代理
        level.add(this.proxyLevelDAO.getThirdCount(id));//获取三级代理
        level.add(this.proxyLevelDAO.getFourthCount(id));//获取四级代理
        level.add(this.proxyLevelDAO.getFiveCount(id));//获取五级代理
        level.add(this.proxyLevelDAO.getSixCount(id));//获取六级代理*/
        long first = this.proxyLevelDAO.getFirstCount(id);
        long secound = this.proxyLevelDAO.getSecondCount(id);
        long third = this.proxyLevelDAO.getThirdCount(id);
        long fourth = this.proxyLevelDAO.getFourthCount(id);
        long five = this.proxyLevelDAO.getFiveCount(id);
        long six = this.proxyLevelDAO.getSixCount(id);
        return new Long[]{first,secound,third,fourth,five,six};
    }

    @Override
    public User findByUserReal(Long id) {
        return this.userDAO.selectUserByUid(id);
    }

    @Override
    public List<Object> getGoodsUpgradeByUserIdPaging(long uid, Integer pageNum) {
        return this.goodsUpgradeRecordDAO.getGoodsUpgradeByUserIdPaging(uid,pageNum);
    }

    @Override
    public Boolean updateUser(User user) {
        return userDAO.update(user);
    }
    @Override
    public User getUserByReferralCode(String referralCode) {
        return userDAO.getUserByReferralCode(referralCode);
    }

    @Override
    public List<RwGoodOrder> getOrdersByUserId(long userid) {
        return rwGoodOrderDAO.getOrdersByUserId(userid);
    }

    @Override
    public List getOdevityAll() {
        return iOdevityDAO.getOdevityAll();
    }

    @Override
    public List getUserFirstLevel(Long uid) {
        return userDAO.getUserFirstLevel(uid);
    }

    @Override
    public UserWithdrawRecord saveUserWithdrawRecord(UserWithdrawRecord userWithdrawRecord) {
        return iUserWithdrawRecordDAO.get(iUserWithdrawRecordDAO.save(userWithdrawRecord));
    }

    @Override
    public List getUserWithdrawRecordAll(int startPage) {
        return iUserWithdrawRecordDAO.getUserWithdrawRecordAll(startPage);
    }

    @Override
    public List getUserWithdrawRecordByStatus(int status, int startPage) {
        return iUserWithdrawRecordDAO.getUserWithdrawRecordByStatus(status,startPage);
    }

    @Override
    public Boolean updateUserWithdrawByStatus(UserWithdrawRecord userWithdrawRecord) {
        return iUserWithdrawRecordDAO.update(userWithdrawRecord);
    }

    @Override
    public UserWithdrawRecord getUserWithdrawRecord(long id) {
        return iUserWithdrawRecordDAO.get(id);
    }
}
